package com.situ.mall.orders.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mysql.cj.jdbc.result.UpdatableResultSet;
import com.situ.mall.orders.model.OrdersModel;
import com.situ.mall.orders.service.impl.OrdersServiceImpl;

import net.sf.json.JSONArray;

@Controller
@RequestMapping("orders")
public class OrdersController {

	@Autowired
	private OrdersServiceImpl ordersServiceImpl;
	
	@RequestMapping(value = "/add")
	@ResponseBody
	public int add(OrdersModel model) {
		int res = ordersServiceImpl.insert(model);
		System.out.println("res="+res);
		return res;
	}
	
	@RequestMapping(value = "/del")
	@ResponseBody
	public int del(OrdersModel model) {
		int res = ordersServiceImpl.delete(model);
		System.out.println(res);
		return res;
	}
	
	@RequestMapping(value = "/upd")
	@ResponseBody
	public int upd(OrdersModel model) {
		int res = ordersServiceImpl.update(model);
		System.out.println("res+++"+res);
		return res;
	}
	
	@RequestMapping(value = "/list",produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public List<OrdersModel> list(OrdersModel model){
		List<OrdersModel> res = ordersServiceImpl.selectAll(model);
		res = JSONArray.fromObject(res);
		System.out.println("res="+res);
		return res;
	}
	
	@RequestMapping(value = "/lists",produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public List<OrdersModel> lists(OrdersModel model){
		List<OrdersModel> res = ordersServiceImpl.selectdemo(model);
		res = JSONArray.fromObject(res);
		System.out.println("res="+res);
		return res;
	}
}
